package com.blb.zycommunity.utils;

import com.blb.zycommunity.entity.SysArea;
import com.blb.zycommunity.entity.SysDept;
import com.blb.zycommunity.entity.SysMenu;
import com.blb.zycommunity.entity.ZyRoom;


import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class TreeUtils {

    /**
     * 菜单表
     * @param treeList
     * @return
     */
    public static List<SysMenu> menusToTree(List<SysMenu> treeList) {
        //操作所有组织机构数据
        Map<Long, List<SysMenu>> groupMap = treeList.stream().collect(Collectors.groupingBy(SysMenu::getParentId));
        treeList.forEach(sysMenu-> {
            sysMenu.setChildren(groupMap.get(sysMenu.getMenuId()));
        });
        List<SysMenu> collect = treeList.stream().filter(sysMenu-> sysMenu.getParentId().equals(0L)).collect(Collectors.toList());
        return collect;
    }

    /**
     * 部门表
     * @param treeList
     * @return
     */
    public static List<SysDept> deptsToTree(List<SysDept> treeList) {
        //操作所有组织机构数据
        Map<Long, List<SysDept>> groupMap = treeList.stream().collect(Collectors.groupingBy(SysDept::getParentId));
        treeList.forEach(sysDept-> {
            sysDept.setChildDepts(groupMap.get(sysDept.getDeptId()));
        });
        List<SysDept> collect = treeList.stream().filter(sysDept-> sysDept.getParentId().equals(0L)).collect(Collectors.toList());
        return collect;
    }

//    /**
//     * 房间表
//     * @param treeList
//     * @return
//     */
//    public static List<ZyRoom> roomToTree(List<ZyRoom> treeList) {
//        //操作所有组织机构数据
//        Map<Long, List<ZyRoom>> groupMap = treeList.stream().collect(Collectors.groupingBy(ZyRoom::getBuildingId));
//        treeList.forEach(zyRoom-> {
//            zyRoom.setRoomId(groupMap.get(ZyRoom.roomId()));
//        });
//        List<SysDept> collect = treeList.stream().filter(sysDept-> sysDept.getParentId().equals(0L)).collect(Collectors.toList());
//        return collect;
//    }

    /**
     * 地区表
     * @return
     */
    public static List<SysArea> areasToTree(List<SysArea> treeList) {
        //操作所有组织机构数据
        Map<Integer, List<SysArea>> groupMap = treeList.stream().collect(Collectors.groupingBy(SysArea::getParentId));
        treeList.forEach(sysArea-> {
            sysArea.setChildren(groupMap.get(sysArea.getCode()));
        });
        List<SysArea> collect = treeList.stream().filter(sysArea-> sysArea.getParentId().equals(0)).collect(Collectors.toList());
        return collect;
    }



}
